package com.google.code.syncgear.servlet;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.google.code.syncgear.core.Environment;
import com.google.code.syncgear.util.MessageUtil;
import com.google.code.syncgear.util.PropertyUtil;

public final class StartupServlet implements Servlet {
	
	private static final Logger log = Logger.getLogger(StartupServlet.class.getName());
	
	@Override
	public void init(ServletConfig servletConfig) throws ServletException {
		log.info(MessageUtil.get("info_startup_int"));
		WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext());
		Environment.setDatastoreService(context.getBean(PropertyUtil.getProperty("syncgear.var.datastore.service")));
		Environment.setCache(context.getBean(PropertyUtil.getProperty("syncgear.var.memcache.service")));
	}

	@Override
	public void destroy() {		
	}

	@Override
	public ServletConfig getServletConfig() {
		return null;
	}

	@Override
	public String getServletInfo() {
		return null;
	}

	@Override
	public void service(ServletRequest arg0, ServletResponse arg1)
			throws ServletException, IOException {		
	}

}
